﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHDJ.Data.Models.Center
{
    /// <summary>
    /// 图说党支部
    /// </summary>
    public class PartyBranchPictureShow : EntityBaseOperation
    {
        /// <summary>
        /// 组织id
        /// </summary>

        public string BranchID { get; set; }

        /// <summary>
        /// Title(保留)
        /// </summary>

        public string Title { get; set; }

        /// <summary>
        /// 图片id
        /// </summary>

        public string ImageID { get; set; }

        /// <summary>
        /// 描述
        /// </summary>

        public string Describe { get; set; }

        public static DataSet GetGridData(int pageIndex, int pageSize, string branchId)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS ID,ImageID,CreateTime from tblPartyBranchPictureShow where 1=1");

            if(!string.IsNullOrEmpty(branchId))
            {
                sb.Append(" and BranchID=?BranchID");
            }

            sb.Append(" order by CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");

            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "BranchID",
                    Value = branchId
                },
                new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "Begin",
                    Value = (pageIndex)*pageSize
                },
                new MySqlParameter()
                {
                    DbType = DbType.Int32,
                    ParameterName = "PageSize",
                    Value = pageSize
                }
            };

            return MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
    }
}
